﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using TeamDev.JQuery.Internals;

public static class jq
{
  private static jqEvents _events = new jqEvents();
  public static jqEvents Event { get { return _events; } }

  private static jqAjax _ajax = new jqAjax();
  public static jqAjax Ajax { get { return _ajax; } }

  public static jqExpression Select(jqBasicSelector selector)
  {
    return new jqExpression(string.Format("$('{0}')", selector.Filter));
  }

  public static jqExpression Select(string element)
  {
    return new jqExpression(string.Format("$('{0}')", element));
  }

  public static jqExpression ToggleAnimationsOnOff()
  {
    return new jqExpression("$.fx.off = !$.fx.off");
  }

  public static jsScriptingBlock Scripting()
  {
    return new jsScriptingBlock();
  }

  public static jqExpression Invoke(string functioname, params string[] args)
  {
    StringBuilder methodinvoke = new StringBuilder();
    methodinvoke.AppendFormat("{0}(", functioname);

    for (int i = 0; i < args.Length; i++)
    {
      if (i > 0) methodinvoke.Append(",");
      methodinvoke.Append(args[i]);
    }

    methodinvoke.Append(")");
    return new jqExpression(methodinvoke.ToString());
  }


  public delegate jqExpression BuildExpressionHandler();
  public static jsFunctionBlock Function(BuildExpressionHandler expression)
  {
    return new jsFunctionBlock() { Expression = expression() };
  }

  public static jsFunctionBlock Function(string functionname, BuildExpressionHandler expression)
  {
    return new jsFunctionBlock() { Expression = expression(), Name = functionname };
  }

  public static jsFunctionBlock Function(string[] args, BuildExpressionHandler expression)
  {
    return new jsFunctionBlock() { Expression = expression(), args = new List<string>(args) };
  }

  public static jsFunctionBlock Function(string functionname, string[] args, BuildExpressionHandler expression)
  {
    return new jsFunctionBlock() { Expression = expression(), Name = functionname, args = new List<string>(args) };
  }


}


